<?php

class MaintainSystemParameter extends MX_Controller {
	function MaintainSystemParameter()
	{
		parent::__construct();
		if(modules::run('login/is_admin_logged_in') == false || modules::run('login/is_supporter_logged_in') == true ){
			if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
				echo OUT_OF_SESSION;
				exit(0);
			}else{redirect('login');}
			return;
		}
	}
	function index()
	{
		$query = "select * from systemparameters";
		$query_rs = $this->db->query($query);
		//$result = $query_rs->result_array();
		$var['params'] = $query_rs->result_array();		
		
		$this->load->model("public_model");	
		$webstoreObj=$this->public_model->getTemplateForUrl();
		$template=$webstoreObj['templatecode'];
		$templateUrl=base_url().'/application/views/templates/'.$template ;
		
		$var['templateUrl'] = $templateUrl;
		
		$content=$this->load->view('systemparameter',$var,true);
		
		Template::display($content);		
	}
	
	function updatesystemparam(){
		if(empty($this->session->userdata['is_logged_in']) || $this->session->userdata['is_logged_in']==false)
		{
			echo "Login". "|" .base_url()."login";
		}	
		else
		{
			$id=$this->input->post('paramId');
			$value=$this->input->post('paramValue');
			$this->db->query("update systemparameters set value = '$value' where id = '$id'");
			
			$name = $this->public_model->getValueFromTableById("systemparameters", "name", "id", $id);
			
			// update action log
			$email = $this->session->userdata('email');
			$name = $this->selectNameParameter($id);
			$action_id = modules::run('actionlog/saveActionLog',ACTION_UPDATE." Systemparamter","Update Systemparamter","","Systemparamter: ".$name[0]->name."->".$value,$email);
						
			//$this->systemParam('The parameter was successfully updated!');
			echo "Pass". "|" ."The parameter was successfully updated!";
		}
	}
	
	function selectNameParameter($id){
		$this->db->select('name');
		$this->db->where('id', $id); 
		$result = $this->db->get('systemparameters');
		return $result->result();
		
		//$result = $this->db->query($strSQL);
		//return $result->result();
	}
	/*
	function updateSystemParam($id,$vakue){
		$this->load->database();
		$strSQL="update wishlist set value='$vakue' where id='$Id'";
		$result=$this->db->query($strSQL);
		return $result;	
	}
	*/
}